<?php

namespace app\admin\model\kd;

use think\Model;


class Order extends Model
{

    

    

    // 表名
    protected $name = 'kd_order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'statuss_text',
        'pickUpStartTime_text',
        'pickUpEndTime_text',
        'payType_text'
    ];
    

    
    public function getStatussList()
    {
        return ['1' => __('Statuss 1'), '2' => __('Statuss 2'), '3' => __('Statuss 3'), '4' => __('Statuss 4'), '5' => __('Statuss 5'), '6' => __('Statuss 6'), '7' => __('Statuss 7'), '8' => __('Statuss 8')];
    }

    public function getPaytypeList()
    {
        return ['1' => __('Paytype 1'), '2' => __('Paytype 2')];
    }


    public function getStatussTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['statuss']) ? $data['statuss'] : '');
        $list = $this->getStatussList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPickupstarttimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pickUpStartTime']) ? $data['pickUpStartTime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getPickupendtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pickUpEndTime']) ? $data['pickUpEndTime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getPaytypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['payType']) ? $data['payType'] : '');
        $list = $this->getPaytypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setPickupstarttimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setPickupendtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
